import pygame
import sys
import time
from dataclasses import dataclass


pygame.init()
screen = pygame.display.set_mode((1280, 720))
clock = pygame.time.Clock()
running = True
dt = clock.tick(60) / 1000.0


@dataclass
class Point:
    type: str = "point"
    x: int = 0
    y: int = 0
    color: str = "balck"


@dataclass
class Line:
    type: str = "line"
    x1: int = 0
    y1: int = 0
    x2: int = 0
    y2: int = 0
    color: str = "balck"


@dataclass
class Circle:
    type: str = "circle"
    x: int = 0
    y: int = 0
    radius: int = 0
    color: str = "balck"


@dataclass
class Rect:
    type: str = "rect"
    x: int = 0
    y: int = 0
    width: int = 0
    height: int = 0
    color: str = "balck"


def move_right(shape, speed):
    if shape.type in ("point", "circle", "rect"):
        if shape.x > screen.get_width():
            return False

        shape.x += speed * dt
    elif shape.type == "line":
        if shape.x1 > screen.get_width() or shape.x2 > screen.get_width():
            return False
        shape.x1 += speed * dt
        shape.x2 += speed * dt
    return True

point = Point(x=10, y=10, color="red")
line = Line(x1=10, y1=15, x2=30, y2=15, color="green")
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        else:
            print(event)

    # 屏幕填充颜色
    screen.fill("blue")

    move_right(point, 20)
    move_right(line, 20)
    # time.sleep(0.1)
    pygame.draw.circle(screen, point.color, (point.x, point.y), 2)
    pygame.draw.line(screen, line.color, (line.x1, line.y1), (line.x2, line.y2), 2)

    # 刷新屏幕
    pygame.display.flip()
    clock.tick(60)  # 限制fps 30帧
